<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
    <meta name="description" content=""/>
    <meta name="author" content=""/>
    <title>Fobia - Bootstrap 4 Web Application UI Kit</title>
    <!--favicon-->
    <link rel="icon" href="assets/images/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="assets/plugins/summernote/dist/summernote-bs4.css"/>
    <!-- simplebar CSS-->
    <link href="assets/plugins/simplebar/css/simplebar.css" rel="stylesheet"/>
    <!-- Bootstrap core CSS-->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" media="screen"/>
    <link href="assets/css/bootstrap-datetimepicker.js" rel="stylesheet"/>
    <!-- animate CSS-->
    <link href="assets/css/animate.css" rel="stylesheet" type="text/css"/>
    <!-- Icons CSS-->
    <link href="assets/css/icons.css" rel="stylesheet" type="text/css"/>
    <!-- Sidebar CSS-->
    <link href="assets/css/sidebar-menu.css" rel="stylesheet"/>
    <!-- Custom Style-->
    <link href="assets/css/app-style.css" rel="stylesheet"/>
    <!-- Dropzone css -->
    <script src="https://www.layuicdn.com/layui/layui.js"></script>
    <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css" />


    <!--<link href="assets/plugins/dropzone/css/dropzone.css" rel="stylesheet" type="text/css">-->

</head>
<style>
    #filename{
        width: 300px;
        height: 100px;
        border: 0px;
    }
</style>
<body>
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-body">
                <ul class="nav nav-pills  bg-facebook nav-justified" role="tablist">

                    <li class="nav-item" style="display: block; width: 300px;">
                        <a class="nav-link" data-toggle="dropdown" href="javascript:void(); "
                           style="display: block; width: 300px;"><i class="icon-settings"></i> <span class="hidden-xs">请选择实训任务</span></a>
                        <div class="dropdown-menu" id="item_1">
                        </div>
                    </li>
                </ul>

                <!-- Tab panes -->
                <div class="tab-content" id="tab">
                    <form action="javascript:void(0)" method="get">
                        <div class="form-group" style="border: dashed 2px rgba(0, 0, 0, 0.3); border-radius: 6px">

                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>


</div>
<!--End Row-->

</body>
<!-- Bootstrap core JavaScript-->
<!-- Bootstrap core JavaScript-->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>

<!-- simplebar js -->
<script src="assets/plugins/simplebar/js/simplebar.js"></script>
<!-- sidebar-menu js -->
<script src="assets/js/sidebar-menu.js"></script>

<!-- Custom scripts -->
<script src="assets/js/app-script.js"></script>
<!-- Dropzone JS  -->
<!--<script src="assets/plugins/dropzone/js/dropzone.js"></script>-->

<script src="assets/plugins/summernote/dist/summernote-bs4.min.js"></script>
<!--Sweet Alerts -->
<script src="assets/plugins/alerts-boxes/js/sweetalert.min.js"></script>
<script>
    function action(res) {

        setTimeout(function () {
            // 这里就是处理的事件
            $(".container.tab-pane").removeClass("active show");
            $("#piil-"+res).addClass("active show")
        }, 500);

    }
    function sweet(id,taskId) {


        var type = "file";          //后台接收时需要的参数名称，自定义即可
        var inputid = "file"+id;            //即input的id，用来寻找值
        var formData = new FormData();
        console.log( inputid)
        formData.append(type,document.getElementById(inputid).files[0]);
        $.ajax({
            type: 'post',
            url: "upload",
            data: formData,
            cache: false,
            processData: false,
            contentType: false,
        }).success(function (data) {
            console.log()
            console.log(data)
            let da = {
                "taskId":taskId,
                "groupId":id,
                "attachment":data.filename,
                "submit":1
            }
            $.ajax({
                url: 'saveResult',
                dataType: 'json',
                type: "post",
                data:da,
                error: function () {
                },
                success: function (data) {
                }
            })

        }).error(function () {

        });


    swal("提交成功！", ""+id, "success");
        }

    // layui.use('upload', function(){
    //     var upload = layui.upload; //得到 upload 对象
    //
    //     //创建一个上传组件
    //     upload.render({
    //         elem: '#file'
    //         ,url: './upload'
    //         ,accept:"file"
    //         ,done: function(res, index, upload){ //上传后的回调
    //             console.log(res,index,upload)
    //             document.getElementById("filename").value=res.filename;
    //         }
    //         //,accept: 'file' //允许上传的文件类型
    //         //,size: 50 //最大允许上传的文件大小
    //         //,……
    //     })
    // });


    $(function () {
        var stno = "";
        var url = window.location.search;
        if (url.indexOf("?") != -1) {
            stno = url.substr(url.indexOf("=") + 1)
        }

        $.ajax({
            url: 'listTaskByStu?stno=' + stno,
            dataType: 'json',
            type: "post",
            error: function () {
            },
            success: function (data) {
                var data = data["date"];
                console.log(data);
                for (var aa = 0; aa < data.length; aa++) {
                    var groupId = data[aa]["groupId"];
                    var stno1 = data[aa]["stno1"];
                    var task = data[aa]["task"];
                    var taskId = task["taskId"];
                    var startDate = task["startDate"];
                    var endDate = task["endDate"];
                    var name = task["tname"];
                    var endDate = task["endDate"];
                    var context = task["content"];
                    var stno2 = data[aa]["stno2"];
                    var stno3 = data[aa]["stno3"];



                    if (aa == 0) {
                            document.getElementById("item_1").innerHTML +=
                                "<a class=\"dropdown-item active\" data-toggle=\"pill\" href=\"#piil-" + groupId + "\" onclick=\"action('"+groupId+"')\"  aria-expanded=\"true\">" + name + "</a>";

                        document.getElementById("tab").innerHTML +=
                            "<div id=\"piil-" + groupId + "\" class=\"container tab-pane active\" style=\"width : 700px\">\n";
                    } else {
                        document.getElementById("item_1").innerHTML +=
                                "<a class=\"dropdown-item\" data-toggle=\"pill\" href=\"#piil-" + groupId + "\" onclick=\"action('"+groupId+"')\" >" + name + "</a>";

                            document.getElementById("tab").innerHTML +=
                            "<div id=\"piil-" + groupId + "\" class=\"container tab-pane fade\" style=\"width : 700px\">\n";
                    }
                    document.getElementById("piil-" + groupId).innerHTML +=
                        "<div class=\"media mb-3\">\n" +
                        "	<div class=\"media-body\">\n" +
                        "		<span class=\"media-meta float-right\">开始时间：" + startDate + "</span><br />\n" +
                        "		<span class=\"media-meta float-right\">结束时间：" + endDate + "</span>" +
                        "		<h4 class=\"m-0\">" + name + "</h4>" +
                        "	</div>" +
                        "</div>" +
                        "<p class=\"form-group\">" +
                        context +
                        "</p>" + "<hr />\n" +
                        "<div class=\"form-group\">" +
                        //"<form action=\"addTResult\" method=\"get\"  >"+
                        "<form action=\"javascript:void(0)\" method=\"get\"  >" +
                        "	<div  class=\"form-group\" style=\"border: dashed 2px rgba(0, 0, 0, 0.3); border-radius: 6px\">" +
                        "		<div class=\"fallback\" id=\"file-dropzone\" >\n" +
                            "<form id=\"uploadForm+"+groupId+"\" enctype=\"multipart/form-data\">\n" +
                        "    文件:<input id=\"file"+groupId+"\"  type=\"file\" name=\"file\"/>\n" +
                        "</form>"+
                        "		</div>" +
                        "	</div>\n" +
                        "			\n" +
                        "	<div class=\"form-group\">" +
                        "		<div style=\"width: 50%; display: block; float: left; padding-left: 25%;\">" +
                        "			<button type=\"button\" class=\"btn btn-primary waves-effect waves-light m-1\" style=\"margin: 0px auto;\"  onclick=\"sweet('"+groupId+"','"+taskId+"')\">" +
                        "				<i class=\"fa fa-floppy-o mr-1\"></i> 提交" +
                        "			</button>" +
                        "		</div>\n" +
                        "		<div  style=\"width: 50%; display: block;float: left; padding-left: 12%;\">" +
                        "		</div>" +
                        "	</div>" +
                        "</form>" +
                        "	</div>" +
                        "</div>\n"
                       ;


                }
            }
        })
    })
</script>

</html>



